package MapBase.logic.decorate.floor
{
	import com.friendsofed.isometric.IsoUtils;
	import com.friendsofed.isometric.Point3D;
	
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class EntityFloor
	{
		private var _obj:Sprite;
		
		private var _recVec:Vector.<Rectangle>;	
		
		public var color:uint = 0x0000FF;
		
		private var _tileWidth : Number;
		private var _tileHeight : Number;
		private var _type : int;
		
		public function EntityFloor(obj:Sprite,tileWidth:Number,tileHeight:Number,recVec:Vector.<Rectangle>,type:int=1)
		{
			_obj = obj;
			_recVec = recVec;
			_tileWidth = tileWidth;
			_tileHeight = tileHeight;
			_type = type;
			
			draw();
		}
		
		public function invalidate():void
		{
			draw();
		}
		
		public function draw():void
		{
			for(var s:int=0;s<_recVec.length;s++)
			{
				var tileW : Number = _tileWidth;
				var tileH : Number = _tileHeight;
				
				var p:Point;

				_obj.graphics.lineStyle(1,0x000000);
				_obj.graphics.beginFill(0x0000FF);
				trace("EntityFloorType",_type);
				if(_type == 1)
				{
					p = IsoUtils.isoToScreen(new Point3D(_recVec[s].x-_obj.x,0,_recVec[s].y-_obj.z));
					_obj.graphics.moveTo(p.x,p.y);
					_obj.graphics.lineTo(p.x-tileW/2,p.y+tileH/2);
					_obj.graphics.lineTo(p.x,p.y+tileH);
					_obj.graphics.lineTo(p.x+tileW/2,p.y+tileH/2);
					_obj.graphics.lineTo(p.x,p.y);
					_obj.graphics.endFill(); 
				}
				else if(_type == 2)
				{
					p = IsoUtils.isoToScreen(new Point3D(_recVec[s].x-_obj.x,0,_recVec[s].y-_obj.z));
					_obj.graphics.moveTo(p.x+tileW/2,p.y);
					_obj.graphics.lineTo(p.x,p.y+tileH/2);
					_obj.graphics.lineTo(p.x,p.y+tileH);
					_obj.graphics.lineTo(p.x+tileW,p.y+tileH/2);
					_obj.graphics.lineTo(p.x+tileW/2,p.y);
					_obj.graphics.endFill(); 
				}
				else if(_type == 3)
				{
					var ps : Point = IsoUtils.isoToScreen(new Point3D(_obj.x,0,_obj.z));
					p = new Point(_recVec[s].x - ps.x, _recVec[s].y - ps.y);
					_obj.graphics.moveTo(p.x+tileH,p.y);
					_obj.graphics.lineTo(p.x,p.y);
					_obj.graphics.lineTo(p.x,p.y+tileH);
					_obj.graphics.lineTo(p.x+tileH,p.y+tileH);
					_obj.graphics.lineTo(p.x+tileH,p.y);
					_obj.graphics.endFill(); 
				}
			}
		}
	}
}